/**
 * 入口文件
 * @param {Array<string>} header
 * @param {Array} data
 * @param {string} filename
 * @param {string} type
 */

export default function(header, data, filename, type = 'xlsx') {
  const isSupportBlob = typeof Blob !== 'undefined'
  if (/^(xls|xlsx|xlsm|xlsb|csv|pdf)$/.test(type.toLowerCase())) {
    isSupportBlob
      ? import('./toXlsx.js').then(excel => {
        excel.export_json_to_excel({ header, data, filename, bookType: type })
      })
      : import('./toXls.js').then(excel => {
        excel.export_json_to_excel(data, filename)
      })
  } else {
    alert(`无法将表格数据导出成 ${ type } 类型文件`)
  }
}
